package com.java.dormitorymanager.mvc.view;

import com.java.dormitorymanager.pojo.Manager;
import com.java.dormitorymanager.pojo.Student;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @program: DormitoryManager
 * @description: 通过姓名查找学生结果显示页面
 * @author: ShuangChenYue
 * @create: 2021-05-16 20:00
 **/
@WebServlet(value = "/ViewSearchStudentByName")
public class ViewSearchStudentByNameServlet extends HttpServlet
{
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    {
        System.out.println("进入通过姓名查找学生的显示界面");
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/html");
        PrintWriter out = resp.getWriter();

        out.println("<!DOCTYPE html>");
        out.println("<html lang=\"en\">");
        out.println("<head>");
        out.println("<meta charset=\"UTF-8\">");
        out.println("<title>显示查询单个学生</title>");
        out.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"http://localhost:8080/DormitoryManager/css/css-student/searchStudentByName.css\">");
        out.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"http://localhost:8080/DormitoryManager/css/css-other/doIcon.css\">");
        out.println("</head>");
        out.println("<body>");
        out.println("<div id=\"divTitle\">");
        out.println("<h1 id=\"h01\">Manage Students</h1>");
        out.println("</div>");
        out.println("<div id=\"div01\">");
        out.println("<h3 class=\"ListName\">searched</h3>");
        out.println("<table class=\"table01\">");
        out.println("<tr class=\"tr01\">");
        out.println("<td>ID</td>");
        out.println("<td>姓名</td>");
        out.println("<td>学号</td>");
        out.println("<td>年龄</td>");
        out.println("<td>操作</td>");
        out.println("</tr>");
        Student student = (Student) req.getAttribute("student");
        out.println("<tr class=\"tr02\">");
        out.println("<td style=\"text-align: center\">"+student.getId()+"</td>");
        out.println("<td>"+student.getName()+"</td>");
        out.println("<td>"+student.getStunum()+"</td>");
        out.println("<td>"+student.getAge()+"</td>");
        out.println("<td><a href=\"/DormitoryManager/mvc/toUpdateStudent.do?id="+student.getId()+"\"><i class=\"iconfontU alterIcon\" title=\"修改\">&#xe700;</i></a> <a href=\"/DormitoryManager/mvc/deleteStudent.do?id="+student.getId()+"\"><i class=\"iconfontU deleteIcon\" title=\"删除\">&#xe614;</i></a> <a href=\"/DormitoryManager/mvc/showStudentDetail.do?id="+student.getId()+"\"><i class=\"iconfontU infoIcon\" title=\"详情\">&#xe611;</i></a></td>");
        out.println("</tr>");
        out.println("</table>");
        out.println("</div>");
        out.println("</body>");
        out.println("</html>");
        out.flush();
        out.close();
    }
}
